package com.edu.web.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.edu.entity.User;
import com.edu.service.impl.UserServiceImpl;

/**
 * Servlet implementation class updetUserServlet
 */
@WebServlet("/updetUserServlet")
public class updetUserServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

   
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		 request.setCharacterEncoding("UTF-8");
			//实例化对象
			UserServiceImpl userServletImpl=new UserServiceImpl();
			//修改用户信息
			User user=new User();
			  String userid = request.getParameter("userid");
		        String occupation = request.getParameter("occp");
		        String userPass = request.getParameter("opass");
		        String userName = request.getParameter("oname");
		        String sex = request.getParameter("osex");
		        String country = request.getParameter("ocou");
		        String email = request.getParameter("oem");
		        String identity = request.getParameter("oiden");
		        
			user.setUserName(userName);
			user.setUserPass(userPass);
			user.setEmail(email);
			user.setOccupation(occupation);
			user.setIdentity(identity);
			user.setCountry(country);
			user.setSex(sex);
			user.setId(Integer.parseInt(request.getParameter("userid")));//获取要修改的用户的id
			boolean b=userServletImpl.update(user);
			request.setAttribute("allUser", userServletImpl.allUser());
			request.getRequestDispatcher("manage-users.jsp").forward(request, response);
	}

}
